﻿using RollCall.Data;
using RollCall.Pages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Navigation;

namespace RollCall.ViewModel
{
    public class RollPageViewModel
    {
        private readonly NavigationService _navigationService;
        public string Type { get; set; }
        public ICommand ReturnCommand { get; set; }
        public ICommand SettingCommand { get; set; }
        public ICommand GroupCommand { get; set; }

        private readonly Subject _subject;
        /// <summary>
        /// 当前科目分组
        /// </summary>
        public ObservableCollection<Data.Group> Groups
        {
            get; set;
        }
        public RollPageViewModel(NavigationService navigationService, string type)
        {
            _navigationService = navigationService;
            Type = type;
            _subject = (Subject)Enum.Parse(typeof(Subject), Type);

            ReturnCommand = new RelayCommand(s =>
              {
                  _navigationService.Navigate(new HomePage());
              }, s => true);
            SettingCommand = new RelayCommand(s =>
            {
                _navigationService.Navigate(new SettingPage(type));
            }, s => true);
            GroupCommand = new RelayCommand(s =>
              {
                  var groupId = (Guid)s;
                  _navigationService.Navigate(new Result(groupId));
              },s=>true);
            //直接写，或者封装
            GetGroups();
        }
        private void GetGroups()
        {
            var list = App.MyDbContext.Groups.Where(w => w.Subject == _subject)
                .ToList();
            Groups = new ObservableCollection<Data.Group>(list);
        }
    }
}
